<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <script src="resource/js/jquery-1.12.3.js"></script>
    <style type="text/css">
        @import "resource/css/newsCSS.css";

    </style>
</head>
<body onload="showComment(<?php echo $_GET['id']?>,1)" >
<?php
session_start();
$id=$_REQUEST["id"];
$conn=new mysqli("localhost","root","123456","htmlkeshe");
$conn->query("set names utf8");

$sql="select * from news where newsId=".$id;
$result=$conn->query($sql);
//        读取一个新闻所有的内容
if($result->num_rows>0) {
    while ($row=$result->fetch_assoc()) {
        $address=$row['newsContent'];
        $time=$row['newsTime'];
        $author=$row['authorName'];
        $title=$row['title'];
        $heat=$row['heat'];
        $picture=$row['newsPic'];
    }
}
//读取文件中的内容
$content = fopen("$address","r") or die("Unable to open file!");
$str ="";
while(!feof($content)){
    $temp= fgets($content);//逐行读取。如果fgets不写length参数，默认是读取1k。

    if(strpos($temp,'iframe') == false){
        $temp = str_replace(" ","&nbsp",$temp);
    }
    $temp = str_replace("\r\n","<br/>",$temp);
    $temp = str_replace("\t","&nbsp&nbsp&nbsp&nbsp",$temp);
//        echo $temp;
    $str.= $temp;
}
$conn->close();
?>

<!--新闻显示-->
<div class="pan">
    <!--    头图-->
    <div id="header" class="header">
        <img src="./resource/img/background/head.jpeg"/>
    </div>
    <div class="main">
        <div class="back">
            <a href="index.php">返回首页</a>
        </div>
        <!--        主要内容-->
        <div class="title">
            <p>
                <?php
                echo $title;
                ?>
            </p>
        </div>
        <div class="author">
            <p>
                <?php
                echo "作者:".$author."&nbsp&nbsp&nbsp&nbsp"."热度：".$heat."&nbsp&nbsp&nbsp&nbsp"."时间:".$time;
                ?>
            </p>
        </div>
        <div class="photo">
            <img src="<?PHP echo $picture; ?>">
        </div>
        <div class="news">

            <?php
            echo $str;
            ?>

        </div>

    </div>
    <!--    评论区-->
    <div class="pinglun">
        <script src="resource/js/news_ajax.js"></script>
        <div class="show"  id="pinglun"  >
            <!--            获取所有的评论-->

        </div>

        <div class="write">
            <p>评论：</p>
            <textarea id="plc" name="pinglun" cols="140" rows="10"></textarea>
        </div>
        <div class="submit">
            <input id="sub" type="button" value="发布" onclick="pinglun(<?php echo $_GET['id']?>)">
        </div>
    </div>
</div>
<div id="FloatDIV" style="border:3px solid black; border-radius: 10px;text-align: center;background-color: #DFF9E9; position: absolute; top: 0px; z-index: 9999;cursor: pointer; width: 25px;height: 100px" onclick="window.scrollTo(0,0);">回到顶部</div>
<script src="resource/js/toTop.js"></script>
<script>
    <?php

    if (isset($_SESSION['name'])){
    ?>
    <?php
    }
    else{
    ?>
    $("#sub").attr("onclick","index()");
    $("#sub").attr("value","回到主页");
    $("#plc").attr("disabled","disabled");
    $("#plc").val("请先登录，之后才能评论哦") ;
    <?php
    }
    ?>
</script>
</body>
</html>
